<!DOCTYPE html>
<html>
    
	<head>
		<meta charset="utf-8">
		<title>通知公告</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
        
		<link rel="import" href="../header.html" id="page1">
		<style>
			/* .mui-pull-bottom-pocket{
				bottom: 50px;
				height: 90px;
			} */
			
			/* .mui-content-padded{
				margin: 5px;
				position: absolute;
				z-index: 10;
				width: 98%;
			} */
			.mui-table-view:before,.mui-table-view:after{
				height: 0px;
			}
			.mui-card{
				margin: 0 5px;
				border-radius: 5px;
			}
			.mui-search{
				margin: 0 5px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">通知公告</h1>
		</header>
		
		<div id="app" class="mui-content" v-cloak>
			
	
			<!--下拉刷新容器-->
			<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
				<div class="mui-content-padded">
					<form action="">
						<div class="mui-input-row mui-search">
							<input id="search" type="search" v-model="dataForm.key" class="mui-input-clear" placeholder="输入公告标题查询">
						</div>
					</form>
				</div>
				<div class="mui-scroll" style="top:50px;">
					<!--数据列表-->
					<ul class="mui-table-view mui-table-view-chevron" style="background-color:#efeff4">
						<li v-for="item in noticeList" class="" style="padding:5px 10px;">
							<div class="mui-card">
								<!--页眉，放置标题-->
								<div class="mui-card-header">{{item.name}}</div>
								<!--内容区-->
								<div class="mui-card-content">
									<div class="mui-card-content-inner">
										{{item.content}}
									</div>
								</div>
								<!--页脚，放置补充信息或支持的操作-->
								<div class="mui-card-footer">
									{{item.createName}} 发布于 {{item.createTime}}
									<a class="mui-card-link" @click="defOpenWindow('file_list','../sys/file-list.html',{'fileIds':item.fileIds||-1})">附件</a>
								</div>
							</div>
						</li> 
					</ul>
					
				</div>
				
			</div>
			
		</div>
		
		<script>
			
			var vm = new Vue({
				el:"#app",
				data:{
					dataForm: {
					  key: ''
					},
					noticeList:[],
					currPage:0,
					totalCount:0,
					totalPage:1
				},
				methods:{
					// 获取通知公告信息
					getNoticeList(type){
						var vmObj = this;
						mui.getJSON(baseUrl+"/buss/busspublicnotice/list",{"page":vmObj.currPage,"limit":10,'name': this.dataForm.key},function(r){
							if (r.code == 0) {
								vmObj.totalCount = r.page.totalCount;
								vmObj.totalPage = r.page.totalPage;
								if(type=="down"){// 下拉刷新
									vmObj.noticeList = r.page.list;
									mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
									if(vmObj.currPage<vmObj.totalPage){
										mui('#pullrefresh').pullRefresh().refresh(true);
									}
									mui.toast("刷新成功");
								}else{// 下拉加载
									vmObj.noticeList = vmObj.noticeList.concat(r.page.list);
									mui('#pullrefresh').pullRefresh().endPullupToRefresh(vmObj.currPage>=vmObj.totalPage); //参数为true代表没有更多数据了。
									mui.toast("加载了"+r.page.list.length+"篇通知");
								}
								
								
							}else{
								mui.toast(r.msg);
							}
						});
					},
					/**
					 * 上拉加载具体业务实现
					 */
					pullupRefresh() {
						// debugger
						if(vm.currPage<vm.totalPage){
							vm.currPage++;
							vm.getNoticeList("up");
						}
						
					},
					/**
					 * 下拉刷新具体业务实现
					 */
					pulldownRefresh() {
						// debugger
						vm.currPage = 1;
						vm.getNoticeList("down");
					}
					
				},
				mounted() {
					mui.init({
						swipeBack: false,
						pullRefresh: {
							container: '#pullrefresh',
							down: {
								style:'circle',
								callback: this.pulldownRefresh
							},
							up: {
								auto:true,
								contentrefresh: '正在加载...',
								callback: this.pullupRefresh
							}
						}
					});
					
					// 搜索框触发事件
					document.getElementById("search").addEventListener("keypress",function(event) {
						if(event.keyCode == "13") {
							document.activeElement.blur();//收起虚拟键盘
							this.pulldownRefresh();//TODO 完成搜索事件
							event.preventDefault(); // 阻止默认事件---阻止页面刷新
						}
					});
				}
			});
			
		</script>
		
	</body>
</html>